package com.zhifa.eurekaclient.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/eureka/test")
public class R {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/list")
    public Object list() {
        Map<String, Object> map = new HashMap<>();
        map.put("a", 1);
        map.put("b", 2);
        map.put("c", 3);
        map.put("eureka", "eureka");
        String body = restTemplate.getForEntity("http://localhost:8081/nacos/test/list", String.class).getBody();
        map.put("eureka_to_nacos", body);
        return map;
    }

    @GetMapping("/err")
    public Object err(HttpServletResponse response) {

        Map<String, Object> map = new HashMap<>();
        map.put("a", 1);
        map.put("b", 2);
        map.put("c", 3);
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return map;
    }
}
